package com.lapelittle.framework.common;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "通用响应结果")
public class Result<T> {
    @Schema(description = "状态码：200成功，其他失败")
    private int code;
    
    @Schema(description = "提示信息")
    private String msg;
    
    @Schema(description = "响应数据")
    private T data;
    
    public Result() {}
    
    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    
    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    
    public static <T> Result<T> ok() {
        return new Result<>(200, "success");
    }
    
    public static <T> Result<T> ok(T data) {
        return new Result<>(200, "success", data);
    }
    
    public static <T> Result<T> ok(String msg, T data) {
        return new Result<>(200, msg, data);
    }
    
    public static <T> Result<T> error() {
        return new Result<>(500, "服务器错误");
    }
    
    public static <T> Result<T> error(String msg) {
        return new Result<>(500, msg);
    }
    
    public static <T> Result<T> error(int code, String msg) {
        return new Result<>(code, msg);
    }
    
    public int getCode() {
        return code;
    }
    
    public void setCode(int code) {
        this.code = code;
    }
    
    public String getMsg() {
        return msg;
    }
    
    public void setMsg(String msg) {
        this.msg = msg;
    }
    
    public T getData() {
        return data;
    }
    
    public void setData(T data) {
        this.data = data;
    }
} 